Adding data to your events topic

Adding data to your events: context and more

There are multiple ways to add extra data to your tracked events, adding richness and value to your dataset:

  1. Event context using self-describing data: Attach event context, describing anything you like, in the form of self-describing JSONs.
  2. Subject: Include information about the user, or the platform on which the event occurred.

Event context

Event context is an incredibly powerful aspect of Snowplow tracking, which allows you to create very rich data. It is based on the same self-describing JSON schemas as the self-describing events. Using event context, you can add any details you like to your events, as long as you can describe them in a self-describing JSON schema.

Each schema will describe a single "entity". All of an event’s entities together form the event context. The event context will be sent as one field of the event, finally ending up in one column (context) in your data storage. There is no limit to how many entities can be attached to one event.

Note that context can be added to any event type, not just self-describing events. This means that even a simple event type like a page view can hold complex and extensive information – reducing the chances of data loss and the amount of modelling (JOINs etc.) needed in modelling, while increasing the value of each event, and the sophistication of the possible use cases.

The entities you provide are validated against their schemas as the event is processed (during the enrich phase). If there is a mistake or mismatch, the event is processed as a Bad Event.

Once defined, an entity can be attached to any kind of event. This is also an important point; it means your tracking is as DRY as possible. Using the same "user" or "image" or "search result" (etc.) entities throughout your tracking reduces error, and again makes the data easier to model.

Example:

tracker.track(
    Structured(category: 'shop', action: 'add-to-basket'),
    contexts: [
        const SelfDescribing(
            schema: 'iglu:com.my_company/movie_poster/jsonschema/1-0-0',
            data: {
                'movie_name': 'Solaris',
                'poster_country': 'JP',
                'poster_date': '1978-01-01'
            }
        ),
        const SelfDescribing(
            schema: 'iglu:com.my_company/customer/jsonschema/1-0-0',
            data: {
                'p_buy': 0.23,
                'segment': 'young_adult'
            }
        )
    ]
);

Adding user and platform data with Subject

Subject information describes the user and device associated with the event, such as their user ID, what type of device they used, or what size screen that device had.

This information can be entered during tracker initialization by passing a SubjectConfiguration instance to the Snowplow.createTracker method. All of the information is optional.

Some subject information is filled automatically by the tracker. This includes the platform of the user, timezone, language, resolution, and viewport.

Please refer to the section on subject configuration on the Configuration page to learn more.

Classes

ConsentGranted Tracking events Adding data to your events
Event used to track a user opting into data collection.
ConsentWithdrawn Tracking events Adding data to your events
Event to track a user withdrawing consent for data collection.
ListItemView Tracking events Adding data to your events
Event tracking the view of an item in a list. If screen engagement tracking is enabled, the list item view events will be aggregated into a screen_summary entity.
PageViewEvent Tracking events Adding data to your events
Event to capture page views on the Web. Not implemented on mobile platforms.
ScreenView Tracking events Adding data to your events
Event to track user viewing a screen within the application.
ScrollChanged Tracking events Adding data to your events
Event tracked when a scroll view's scroll position changes. If screen engagement tracking is enabled, the scroll changed events will be aggregated into a screen_summary entity.
SelfDescribing Tracking events Adding data to your events
Event to track custom information that does not fit into the out-of-the box events.
Structured Tracking events Adding data to your events
Event to capture custom consumer interactions without the need to define a custom schema.
Timing Tracking events Adding data to your events
Event used to track user timing events such as how long resources take to load.